package vm;

import java.util.ArrayList;

/**
 * @author zzb
 * @since 2021-01-26
 */
public class OOMObject {
  static class OOMObject1 {
  public byte[] placeholder = new byte[64 * 1024];
}

public static void fillHeap(int num) throws InterruptedException {
  ArrayList<OOMObject> list = new ArrayList<>();
  for (int i = 0; i < num; i++) {
    Thread.sleep(50);
    list.add(new OOMObject());
  }
  System.gc();
}

  public static void main(String[] args) throws InterruptedException {
    Thread.sleep(3000);
    fillHeap(1000);
  }

}
